class Solution(object):
    def findSmallestSetOfVertices(self, n, edges):
        p = [0] * n
        for _, v in edges:
            p[v] += 1
        out = []
        for i in range(n):
            if not p[i]:
                out.append(i)
        return out